package com.project.service.impl;

import com.project.entity.po.Flow;
import com.project.exception.ServiceException;
import com.project.mapper.FlowMapper;
import com.project.result.ResponseResult;
import com.project.result.ResultCode;
import com.project.service.FlowService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FlowServiceImpl implements FlowService {
    @Resource
    FlowMapper flowMapper;

    @Override
    public ResponseResult<List<Flow>> selectAllFlow() {
        List<Flow> list = flowMapper.selectAllFlow();
        if(list.size()==0){
            throw new ServiceException(ResultCode.ERROR);
        }
        return ResponseResult.success(ResultCode.SUCCESS,list);
    }


    @Override
    public ResponseResult<List<Flow>> selectFlowByName(String name) {
        List<Flow> list = flowMapper.selectFlowByName(name);
        if(list.size()==0){
            throw new ServiceException(ResultCode.ERROR);
        }
        return ResponseResult.success(ResultCode.SUCCESS,list);
    }


    @Override
    public ResponseResult<Integer> updateFlowById(Long id) {
        int i = flowMapper.updateFlowById(id);
        if(i == 0){
            throw new ServiceException(ResultCode.ERROR);
        }
        return ResponseResult.success(ResultCode.SUCCESS,i);
    }


    @Override
    public ResponseResult<Flow> selectFlowById(Long id) {
        Flow flow = flowMapper.selectFlowById(id);
        if(flow == null){
            throw new ServiceException(ResultCode.ERROR);
        }
        return ResponseResult.success(ResultCode.SUCCESS,flow);
    }


    @Override
    public ResponseResult<Integer> insertFlow(Flow flow) {
        int i = flowMapper.insertFlow(flow);
        if(i == 0){
            throw new ServiceException(ResultCode.ERROR);
        }
        return ResponseResult.success(ResultCode.SUCCESS,i);
    }


    @Override
    public ResponseResult<Integer> updateFlow(Flow flow) {
        int i = flowMapper.updateFlow(flow);
        if(i == 0){
            throw new ServiceException(ResultCode.ERROR);
        }
        return ResponseResult.success(ResultCode.SUCCESS,i);
    }
}
